How to make if else Condition in Adv. SQL Query? | 您所在的位置:网站首页 › homezipcode 纽约 › How to make if else Condition in Adv. SQL Query? |
Hello Roshan, The CASE condition would be a good choice for your requirement. Regarding your note, you don't have to worry about data types if your HomeZipCode output structure has an attribute of type Text - if you try to store an Integer in it, it will be implicitly converted to a string. I don't know what error you're receiving, but I suspect the issue is that a CASE can only return one datatype (or multiple datatypes if they can be implicitly converted). So this will return an error, because it will return a string or an integer: SELECT CASE WHEN 0 = 0 THEN 'Hello' ELSE 1 END as HomeZipCodebut this will not, since it only returns strings: SELECT CASE WHEN 0 = 0 THEN 'Hello' ELSE '1' END as HomeZipCodeAll you need to do is convert or cast your HomeZipCode into a String in the CASE branch, something like this: CASE WHEN {Customers}.[HomeZipCode]=0 THEN 'Hello' ELSE CONVERT(varchar, {Customers}.[HomeZipCode]) END as HomeZipCodeand since your CASE now only returns strings, you shouldn't receive any errors. |
CopyRight 2018-2019 实验室设备网 版权所有 |